/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Carretilla.java
 *
 * Created on 14-mar-2012, 21:17:56

 */

package Ventas;

import Ventas.procsventas.classprocs;
import java.awt.Dimension;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author macbookpro
 */

public class Carretilla extends javax.swing.JFrame {
classprocs procedimientos= new classprocs();
public static ArrayList<DatosCarreta> CarretillaActual;
java.sql.ResultSet rs, rs2; 
static int acutabla3;
static int numdeitems;
    /** Creates new form Carretilla */
    public Carretilla() {
        initComponents();
        CarretillaActual= new ArrayList<DatosCarreta>();
 
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane2.setViewportView(jTable2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N
        setResizable(false);
        setSize(new java.awt.Dimension(1060, 600));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tiendaingsoftii.TiendaINGSOFTIIApp.class).getContext().getResourceMap(Carretilla.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}

            },
            new String [] {
                "Codigo", "Nombre", "Tipo", "Marca", "Precio Venta", "Existencia", "Descripcion"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setIcon(resourceMap.getIcon("")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setEnabled(false);
        jTextField2.setName("jTextField2"); // NOI18N
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField2KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setEnabled(false);
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField1KeyPressed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre", "Codigo", "Nombre y Marca" }));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jButton4.setFont(resourceMap.getFont("jButton4.font")); // NOI18N
        jButton4.setIcon(resourceMap.getIcon("")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(476, 476, 476)
                .add(jLabel1))
            .add(layout.createSequentialGroup()
                .add(40, 40, 40)
                .add(jLabel2)
                .add(25, 25, 25)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 640, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(40, 40, 40)
                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 205, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(40, 40, 40)
                .add(jLabel4)
                .add(53, 53, 53)
                .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 640, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(40, 40, 40)
                .add(jButton1))
            .add(layout.createSequentialGroup()
                .add(410, 410, 410)
                .add(jLabel3))
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 1010, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(22, 22, 22)
                .add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 332, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(6, 6, 6)
                .add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 332, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(6, 6, 6)
                .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 332, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jLabel1)
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel2))
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(2, 2, 2)
                        .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel4))
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(jButton1)))
                .add(15, 15, 15)
                .add(jLabel3)
                .add(8, 8, 8)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 219, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(7, 7, 7)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
     
        if((jTable1.getSelectedRow() >= 0)){//si no se hace la busqueda
    if ((jTable1.getValueAt(jTable1.getSelectedRow(),1) !=null)&&(jTable1.getValueAt(jTable1.getSelectedRow(),5).toString().compareTo("0"))!=0){//a nivel de objetos se compara si es nula la casilla
                                                                                    //no se agregan productos a la carretilla que no tengan existencias
        DatosCarreta productoactual=new DatosCarreta();
        productoactual.setCodigo(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),0)));
        productoactual.setNombre(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),1)));
        productoactual.setTipo(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),2)));
        productoactual.setMarca(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),3)));
        productoactual.setPrecioventa(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),4)));
        productoactual.setExistencia(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),5)));
        productoactual.setDescripcion(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),6)));
   
        CarretillaActual.add(productoactual);
        
        
    JOptionPane.showMessageDialog(null, "Producto Agregado a Carretilla");

}else{
    JOptionPane.showMessageDialog(null, "Casilla en Blanco O Producto sin existencias por favor seleccione un producto con existencias y haciendo una busqueda");
    
    }
        
        
         }else{
        
         JOptionPane.showMessageDialog(null, "Por Favor busque un producto y luego seleccionelo para agregarlo a Carretilla");
   
        } 
    
   
     
     
     
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased
        // TODO add your handling code here:
}//GEN-LAST:event_jTextField2KeyReleased

    private void jTextField2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyPressed
        
        if(evt.getKeyCode()==10){
            
            if(jComboBox1.getSelectedItem().toString().compareTo("Nombre y Marca")==0){
                jTextField2.setEnabled(true);
                jLabel4.setEnabled(true);
                try {
                    Vector tableData = new Vector();
                    Vector<String> tableHeaders = new Vector<String>();
                    
                    
                    
                    tableHeaders.add("Codigo");
                    tableHeaders.add("Nombre");
                    tableHeaders.add("Tipo");
                    tableHeaders.add("Marca");
                    tableHeaders.add("Precio Venta");
                    tableHeaders.add("Existencia");
                    tableHeaders.add("Descripcion");
                    
                    
                    Vector<Object> oneRow = null;
                    
                    rs=procedimientos.Verproductosprmarcaynombre(jTextField1.getText(), jTextField2.getText());
                    int recorre=0;
                    while (rs.next()){
                        
                        
                        
                        String cod=rs.getObject(1).toString();
                        String nom=rs.getObject(2).toString();
                        String tip=rs.getObject(3).toString();
                        String Marc=rs.getObject(4).toString();
                        String Prv=rs.getObject(5).toString();
                        String exi=rs.getObject(6).toString();
                        String Stm=rs.getObject(7).toString();
                        
                        oneRow = new Vector<Object>();
                        oneRow.add(cod);
                        oneRow.add(nom);
                        oneRow.add(tip);
                        oneRow.add(Marc);
                        oneRow.add(Prv);
                        oneRow.add(exi);
                        oneRow.add(Stm);
                        
                        
                        tableData.add(oneRow);
                        
                    }
                    
                    jTable1.setModel(new MiModelo(tableData, tableHeaders));
                } catch (SQLException ex) {
                    Logger.getLogger(Carretilla.class.getName()).log(Level.SEVERE, null, ex);
                
                }
                
                
                
            }
        }
    }//GEN-LAST:event_jTextField2KeyPressed

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
        
        if (evt.getKeyCode()==10){
            if(jComboBox1.getSelectedItem().toString().compareTo("Codigo")==0){
                try {
                    Vector tableData = new Vector();
                    Vector<String> tableHeaders = new Vector<String>();
                    
                    
                    
                    tableHeaders.add("Codigo");
                    tableHeaders.add("Nombre");
                    tableHeaders.add("Tipo");
                    tableHeaders.add("Marca");
                    tableHeaders.add("Precio Venta");
                    tableHeaders.add("Existencia");
                    tableHeaders.add("Descripcion");
                    
                    
                    Vector<Object> oneRow = null;
                    
                    rs=procedimientos.Verproductosprcodigo(jTextField1.getText());
                    int recorre=0;
                    while (rs.next()){
                        
                        
                        
                        String cod=rs.getObject(1).toString();
                        String nom=rs.getObject(2).toString();
                        String tip=rs.getObject(3).toString();
                        String Marc=rs.getObject(4).toString();
                        String Prv=rs.getObject(5).toString();
                        String exi=rs.getObject(6).toString();
                        String Stm=rs.getObject(7).toString();
                        
                        oneRow = new Vector<Object>();
                        oneRow.add(cod);
                        oneRow.add(nom);
                        oneRow.add(tip);
                        oneRow.add(Marc);
                        oneRow.add(Prv);
                        oneRow.add(exi);
                        oneRow.add(Stm);
                        
                        
                        tableData.add(oneRow);
                        
                    }
                    
                    jTable1.setModel(new MiModelo(tableData, tableHeaders));
                jTable1.setCellSelectionEnabled(true);
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, "ha ocurrido un error de parte del gestor de BD por favor reinicie el software o consulte a su proveedor");
                    
                    Logger.getLogger(Carretilla.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
                
            }//fin primer if
            if(jComboBox1.getSelectedItem().toString().compareTo("Nombre")==0){
                try {
                    Vector tableData = new Vector();
                    Vector<String> tableHeaders = new Vector<String>();
                    
                    
                    
                    tableHeaders.add("Codigo");
                    tableHeaders.add("Nombre");
                    tableHeaders.add("Tipo");
                    tableHeaders.add("Marca");
                    tableHeaders.add("Precio Venta");
                    tableHeaders.add("Existencia");
                    tableHeaders.add("Descripcion");
                    
                    
                    Vector<Object> oneRow = null;
                    
                    rs=procedimientos.Verproductosprnombre(jTextField1.getText());
                    int recorre=0;
                    while (rs.next()){
                        
                        
                        
                        String cod=rs.getObject(1).toString();
                        String nom=rs.getObject(2).toString();
                        String tip=rs.getObject(3).toString();
                        String Marc=rs.getObject(4).toString();
                        String Prv=rs.getObject(5).toString();
                        String exi=rs.getObject(6).toString();
                        String Stm=rs.getObject(7).toString();
                        
                        oneRow = new Vector<Object>();
                        oneRow.add(cod);
                        oneRow.add(nom);
                        oneRow.add(tip);
                        oneRow.add(Marc);
                        oneRow.add(Prv);
                        oneRow.add(exi);
                        oneRow.add(Stm);
                        
                        
                        tableData.add(oneRow);
                        
                    }
                
                    jTable1.setModel(new MiModelo(tableData, tableHeaders));
                  
               
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, "ha ocurrido un error de parte del gestor de BD por favor reinicie el software o consulte a su proveedor");
                    
                    Logger.getLogger(Carretilla.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                JOptionPane.showMessageDialog(null, "el numero de filas es "+jTable1.getRowCount());
                
            }////fin segundo if
            
            
            if(jComboBox1.getSelectedItem().toString().compareTo("Nombre y Marca")==0){
                jTextField2.setEnabled(true);
                jLabel4.setEnabled(true);
                try {
                    Vector tableData = new Vector();
                    Vector<String> tableHeaders = new Vector<String>();
                    
                    
                    
                    tableHeaders.add("Codigo");
                    tableHeaders.add("Nombre");
                    tableHeaders.add("Tipo");
                    tableHeaders.add("Marca");
                    tableHeaders.add("Precio Venta");
                    tableHeaders.add("Existencia");
                    tableHeaders.add("Descripcion");
                    
                    
                    Vector<Object> oneRow = null;
                    
                    rs=procedimientos.Verproductosprmarcaynombre(jTextField1.getText(), jTextField2.getText());
                    int recorre=0;
                    while (rs.next()){
                        
                        
                        
                        String cod=rs.getObject(1).toString();
                        String nom=rs.getObject(2).toString();
                        String tip=rs.getObject(3).toString();
                        String Marc=rs.getObject(4).toString();
                        String Prv=rs.getObject(5).toString();
                        String exi=rs.getObject(6).toString();
                        String Stm=rs.getObject(7).toString();
                        
                        oneRow = new Vector<Object>();
                        oneRow.add(cod);
                        oneRow.add(nom);
                        oneRow.add(tip);
                        oneRow.add(Marc);
                        oneRow.add(Prv);
                        oneRow.add(exi);
                        oneRow.add(Stm);
                        
                        
                        tableData.add(oneRow);
                        
                    }
                    
                    
                    jTable1.setModel(new MiModelo(tableData, tableHeaders));
                    
               
                } catch (SQLException ex) {
                    Logger.getLogger(Carretilla.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
                
            }
            
            
            
        }//fin if que compara si es una tecla enter la que se presiono
}//GEN-LAST:event_jTextField1KeyPressed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed



    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged

        if(evt.getItem().toString().compareTo("Nombre y Marca")==0){

        jTextField2.setEnabled(true);
        jLabel4.setEnabled(true);
        }
        else{
        jTextField2.setEnabled(false);
        jLabel4.setEnabled(false);
        
        
        
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
if(CarretillaActual.isEmpty()!=true){
VerEditarCarreta micarreta=new VerEditarCarreta();
micarreta.setVisible(true);

}else{
JOptionPane.showMessageDialog(null, "La Carretilla actual se Encuentra Vacia, Por favor agregue un Producto a su Carretilla");
}
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        Descripcionprod midescripcion = new Descripcionprod();
        midescripcion.inicializar(true, false);
        midescripcion.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       
if(CarretillaActual.size()>0){

        venta ventactual=new venta();
        ventactual.setVisible(true);
        

}else{

    JOptionPane.showMessageDialog(null, "Debe por lo menos de haber 1 Producto en Carretilla");
}        
        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
       if(evt.getKeyCode()==10){
            
        if((jTable1.getSelectedRow() >= 0)){//si no se hace la busqueda
    if ((jTable1.getValueAt(jTable1.getSelectedRow(),1) !=null)&&(jTable1.getValueAt(jTable1.getSelectedRow(),5).toString().compareTo("0"))!=0){//a nivel de objetos se compara si es nula la casilla
                                                                                    //no se agregan productos a la carretilla que no tengan existencias
        DatosCarreta productoactual=new DatosCarreta();
        productoactual.setCodigo(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),0)));
        productoactual.setNombre(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),1)));
        productoactual.setTipo(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),2)));
        productoactual.setMarca(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),3)));
        productoactual.setPrecioventa(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),4)));
        productoactual.setExistencia(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),5)));
        productoactual.setDescripcion(String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(),6)));
   
        CarretillaActual.add(productoactual);
        
        
    JOptionPane.showMessageDialog(null, "Producto Agregado a Carretilla");

}else{
    JOptionPane.showMessageDialog(null, "Casilla en Blanco O Producto sin existencias por favor seleccione un producto con existencias y haciendo una busqueda");
    
    }
        
        
         }else{
        
         JOptionPane.showMessageDialog(null, "Por Favor busque un producto y luego seleccionelo para agregarlo a Carretilla");
   
        } 
    
   
     
     
     
       }
    }//GEN-LAST:event_jTable1KeyPressed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Carretilla().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    public static javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
